package Simulator;

import java.util.Date;
import java.util.Random;


/**
 * Class QuotaZone
 * Zone pour généré les quota
 */
public class QuotaZone {
    /**
     * Heure de debut de la zone
     */
    private int startHour;
    /**
     * Heure de fin de la zone
     */
    private int endHour;
    /**
     * Jour de debut de la zone
     */
    private int startWeekDay;
    /**
     * Jour de fin de la zone
     */
    private int endWeekDay;
    /**
     * Nombre de demande par heure
     */
    private int dailyRequestNumber;
    /**
     * Nombre de demande envoyer dans l'heure
     */
    private int dailySendedRequestNumber;
    /**
     * Etage du debut de la zone appelante
     */
    private int startCallerZone;
    /**
     * Etage de fin de la zone appelante
     */
    private int endCallerZone;
    /**
     * Etage du debut de la zone de destination
     */
    private int startTargetZone;
    /**
     * Etage de fin de la zone de destination
     */
    private int endTargetZone;
    /**
     * Simulator pour ajouter des demande
     */
    private Simulator s;



    /**
     * Constructeur
     * @param s Simulateur
     */
    public QuotaZone (Simulator s) {
	    this.s = s;
    };

    /**
     * Set the value of startHour
     * Heure de debut de la zone
     * @param newVar the new value of startHour
     */
    public void setStartHour ( int newVar ) {
        startHour = newVar;
    }

    /**
     * Get the value of startHour
     * Heure de debut de la zone
     * @return the value of startHour
     */
    public int getStartHour ( ) {
        return startHour;
    }

    /**
     * Set the value of endHour
     * Heure de fin de la zone
     * @param newVar the new value of endHour
     */
    public void setEndHour ( int newVar ) {
        endHour = newVar;
    }

    /**
     * Get the value of endHour
     * Heure de fin de la zone
     * @return the value of endHour
     */
    public int getEndHour ( ) {
        return endHour;
    }

    /**
     * Set the value of startWeekDay
     * Jour de debut de la zone
     * @param newVar the new value of startWeekDay
     */
    public void setStartWeekDay ( int newVar ) {
        startWeekDay = newVar;
    }

    /**
     * Get the value of startWeekDay
     * Jour de debut de la zone
     * @return the value of startWeekDay
     */
    public int getStartWeekDay ( ) {
        return startWeekDay;
    }

    /**
     * Set the value of endWeekDay
     * Jour de fin de la zone
     * @param newVar the new value of endWeekDay
     */
    public void setEndWeekDay ( int newVar ) {
        endWeekDay = newVar;
    }

    /**
     * Get the value of endWeekDay
     * Jour de fin de la zone
     * @return the value of endWeekDay
     */
    public int getEndWeekDay ( ) {
        return endWeekDay;
    }

    /**
     * Set the value of hourlyRequestNumber
     * Nombre de demande par heure
     * @param newVar the new value of hourlyRequestNumber
     */
    public void setDailyRequestNumber ( int newVar ) {
        dailyRequestNumber = newVar;
    }

    /**
     * Get the value of hourlyRequestNumber
     * Nombre de demande par heure
     * @return the value of hourlyRequestNumber
     */
    public int getDailyRequestNumber ( ) {
        return dailyRequestNumber;
    }

    /**
     * Set the value of hourlySendedRequestNumber
     * Nombre de demande envoyer dans l'heure
     * @param newVar the new value of hourlySendedRequestNumber
     */
    public void setDailySendedRequestNumber ( int newVar ) {
        dailySendedRequestNumber = newVar;
    }

    /**
     * Get the value of hourlySendedRequestNumber
     * Nombre de demande envoyer dans l'heure
     * @return the value of hourlySendedRequestNumber
     */
    public int getDailySendedRequestNumber ( ) {
        return dailySendedRequestNumber;
    }

    /**
     * Set the value of startCallerZone
     * Etage du debut de la zone appelante
     * @param newVar the new value of startCallerZone
     */
    public void setStartCallerZone ( int newVar ) {
        startCallerZone = newVar;
    }

    /**
     * Get the value of startCallerZone
     * Etage du debut de la zone appelante
     * @return the value of startCallerZone
     */
    public int getStartCallerZone ( ) {
        return startCallerZone;
    }

    /**
     * Set the value of endCallerZone
     * Etage de fin de la zone appelante
     * @param newVar the new value of endCallerZone
     */
    public  void setEndCallerZone ( int newVar ) {
        endCallerZone = newVar;
    }

    /**
     * Get the value of endCallerZone
     * Etage de fin de la zone appelante
     * @return the value of endCallerZone
     */
    public int getEndCallerZone ( ) {
        return endCallerZone;
    }

    /**
     * Set the value of startTargetZone
     * Etage du debut de la zone de destination
     * @param newVar the new value of startTargetZone
     */
    public void setStartTargetZone ( int newVar ) {
        startTargetZone = newVar;
    }

    /**
     * Get the value of startTargetZone
     * Etage du debut de la zone de destination
     * @return the value of startTargetZone
     */
    public int getStartTargetZone ( ) {
        return startTargetZone;
    }

    /**
     * Set the value of endTargetZone
     * Etage de fin de la zone de destination
     * @param newVar the new value of endTargetZone
     */
    public void setEndTargetZone ( int newVar ) {
        endTargetZone = newVar;
    }

    /**
     * Get the value of endTargetZone
     * Etage de fin de la zone de destination
     * @return the value of endTargetZone
     */
    public int getEndTargetZone ( ) {
        return endTargetZone;
    }

    /**
     * Lance une requete
     * @param currentDate date actuel
     */
    public void sendRequest(Date currentDate){
	    Date launch;
	    int startLevel,endLevel,weigth;
	    boolean urgent;
	    Random randGenerator = new Random();

	    if(this.getStartCallerZone() != this.getEndCallerZone()){
		startLevel = this.getStartCallerZone() + randGenerator.nextInt(Math.abs(this.getStartCallerZone()-this.getEndCallerZone()));
	    }
	    else{
		    startLevel = this.getStartCallerZone();
	    }
	    if(this.getStartTargetZone() != this.getEndTargetZone()){
		    endLevel = this.getStartTargetZone() + randGenerator.nextInt(Math.abs(this.getStartTargetZone()-this.getEndTargetZone()));
	    }
	    else{
		    endLevel = this.getStartTargetZone();
	    }

	    // 5% des demandes seront des urgences
	    urgent = (randGenerator.nextInt(100)<2);
	    //urgent = false;

	    //Entre 1 et 4 personne prenne l'ascenseur
	    //Elles font entre 50 et 90kg chacunne
	    int nbPersons = 1+randGenerator.nextInt(4);
	    int weight = 0;
	    for(int j=0;j<nbPersons;j++){
		    weight += (50 + randGenerator.nextInt(40));
	    }

	    //Generation de la date de lancement
	    //Par rapport a la date actuelle, on ajoute entre 0 et 3600 secondes.
	    launch = (Date)currentDate.clone();
	    launch.setTime(launch.getTime()+(randGenerator.nextInt(3600)*1000));

	    this.dailySendedRequestNumber++;
	    s.addRequest(launch, startLevel, endLevel, weight, urgent);
    }

    /**
     * Réinitialise le nombre de requete lancé
     */
    public void init(){
	    this.dailySendedRequestNumber = 0;
    }

}
